package class_and_object.homework;

import java.util.Scanner;

/**
 * 12.5
 *
 * @author haomin
 * @date 2022/05/30 22:56
 **/

public class Triangle {
    private double side1;
    private double side2;
    private double side3;

    public Triangle() {
    }

    public Triangle(double side1, double side2, double side3) throws IllegalTriangleException {
        if (side1 + side2 < side3 || side1 + side3 < side2 || side2 + side3 < side1) {
            throw new IllegalTriangleException("在三角形中，任意两边之和总大于第三边");
        }
        System.out.print("能构成三角形\n");
    }

    public double getSide1() {
        return side1;
    }

    public void setSide1(double side1) {
        this.side1 = side1;
    }

    public double getSide2() {
        return side2;
    }

    public void setSide2(double side2) {
        this.side2 = side2;
    }

    public double getSide3() {
        return side3;
    }

    public void setSide3(double side3){
        this.side3 = side3;
    }

    public class IllegalTriangleException extends Exception {
        public IllegalTriangleException() {
            super();
        }

        public IllegalTriangleException(String message) {
            super(message);
        }
    }

    public static class Test {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            while (true) {
                System.out.print("Enter three sides for a triangle: ");
                try {
                    double side1 = input.nextDouble();
                    double side2 = input.nextDouble();
                    double side3 = input.nextDouble();
                    Triangle triangle = new Triangle(side1, side2, side3);
                } catch (IllegalTriangleException ex) {
                    System.out.println(ex.getMessage());
                    System.out.println("Try again.");
                }
                input.nextLine();
            }
        }
    }
}